/*
ControlsFactoryTest
*/

ControlsFactory{

	var presetLoader, controlsHolder, synthType;

	*new{|preset|
		var o;
		o = super.new.init;
		o.setPreset(preset);
		^o;
	}
	
	init{
		controlsHolder = RippleSLControls.new;
	}
	
	setSynthType{|type|
		synthType = type;		
	}
	
	makeControlsList{
		
		var controlsList, c, val, randAmt, midiControlNumbers;
		
		controlsList = MPOrderedEnvir.new;
		
		midiControlNumbers = Dictionary.new;
		
		controlsHolder.setMidiControlNumbers(midiControlNumbers);
		
		c = controlsHolder.getDescriptor;
				
		c.keysValuesDo{ |name, cDesc|
			var cd, test, val, control;
			cd = c.at(name);
			val = presetLoader.getVal(val: cd.default, index: name);
			randAmt =  presetLoader.getVal(val: 0, index: (name.asString ++ "RandAmt").asSymbol );

			control = cDesc;
			control.name = name;
			control.setParent(controlsHolder);
			control.setInitialValue(val);
			control.setRandValue(randAmt);
			
//			control = cDesc.getControlClass.new(
//					name, 
//					min: cd.min, 
//					max: cd.max, 
//					midiNum: cd.midiNum, 
//					theLog: cd.theLog,
//					postLaunch: cd.postLaunch, 
//					sequenceLet: controlsHolder, 
//					val: val,
//					randArg: randAmt  
//				);
			
			controlsList.put(	name, control);
			if(cd.midiNum != nil){
				midiControlNumbers.add(cd.midiNum -> control);
			};		
		};
		
		^controlsList;
	}
	
	setPreset{|presetArg|
		presetLoader = PresetLoader.new;
		presetLoader.preset = presetArg;
	}

	makeControls{|preset|
		var desc;
	
		desc = synthType.new;
		controlsHolder.setDescriptor(desc);
		
		^controlsHolder.setControlsList( this.makeControlsList );
			
	}
	



}